package cn.diancan.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Version;

import cn.diancan.util.DateUtil;

 
 
/**
 * 角色表
 * @author 
 *
 */
@Entity
public class SysRole implements Serializable{
    	
	/**
     * 
     */
    private static final long serialVersionUID = -4450233630238960735L;
	private Long    id;          //id
	private String name;     //角色名称
	private String description;     //角色描述
	private String creationDate; //创建时间
	private String modificationDate;//修改时间
	private Integer enable;      //是否可用 1：可用 0：禁用
	private Integer isDelete;     //是否删除 0:未删除 1：删除
	    private Integer version;
	    
	    @Version
	    @Column(name="OPTLOCK",columnDefinition="int(11) DEFAULT 0")
	    public Integer getVersion() {
	        return version;
	    }
	    public void setVersion(Integer version) {
	        this.version = version;
	    }
	private Set<SysAuthority> ymAuthorities=new HashSet<SysAuthority>();//权限集合
	private Set<SysManager> ymManagers=new HashSet<SysManager>();//用户集合
	public SysRole() {
		this.creationDate = DateUtil.currentDateTime();
		this.modificationDate= DateUtil.currentDateTime();
		this.enable=1;
		this.isDelete=0;
	}

	
	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	@Column(name="creationDate",columnDefinition="DATETIME",length=19)
	public String getCreationDate() {
		return creationDate;
	}
	public void setCreationDate(String creationDate) {
		this.creationDate = DateUtil.getMysqlDateTime(creationDate);
	}
	@Column(name="modificationDate",columnDefinition="DATETIME",length=19)
	public String getModificationDate() {
		return modificationDate;
	}
	public void setModificationDate(String modificationDate) {
		this.modificationDate =DateUtil.getMysqlDateTime(modificationDate);
	}

	public Integer getEnable() {
		return enable;
	}

	public void setEnable(Integer enable) {
		this.enable = enable;
	}

	public Integer getIsDelete() {
	    return isDelete;
	}

	public void setIsDelete(Integer isDelete) {
	    this.isDelete = isDelete;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToMany(
		targetEntity=SysAuthority.class,
		cascade={CascadeType.PERSIST,CascadeType.MERGE },
		fetch=FetchType.EAGER
		)
	@JoinTable(
		name="Sysrole_authority",
		joinColumns=@JoinColumn(name="roleId"),
		inverseJoinColumns=@JoinColumn(name="authorityId")
		)

	public Set<SysAuthority> getYmAuthorities() {
		return ymAuthorities;
	}


	public void setYmAuthorities(Set<SysAuthority> ymAuthorities) {
		this.ymAuthorities = ymAuthorities;
	}


	@ManyToMany(
			cascade={CascadeType.PERSIST,CascadeType.MERGE },
			mappedBy="roles",
			targetEntity=SysManager.class
			
			)
	public Set<SysManager> getYmManagers() {
		return ymManagers;
	}


	public void setYmManagers(Set<SysManager> ymManagers) {
		this.ymManagers = ymManagers;
	}
}
